package com.iscreen.core.services.downloader;

import java.io.Serializable;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.MessageListener;

import com.iscreen.core.utils.jms.BaseMDB;
import com.iscreen.core.utils.jms.IScreenQueues;
import com.iscreen.utils.exceptions.IScreenException;

/**
 * Message-Driven Bean implementation class for: DownloaderMDB
 * 
 */
@MessageDriven(activationConfig = {
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(propertyName = "destination", propertyValue = IScreenQueues.DOWNLOAD_QUEUE) })
public class DownloaderMDB extends BaseMDB implements MessageListener
{
	@EJB
	private Downloader downloader;

	/**
	 * Default constructor.
	 */
	public DownloaderMDB()
	{
	}

	@Override
	protected Object processMessage(Serializable message) throws IScreenException
	{
		DownloadMessage downloadMessage = (DownloadMessage) message;
		System.out.println(downloadMessage.getSource() + " -> "
				+ downloadMessage.getDestination());
		downloader.download(downloadMessage);
		return downloadMessage.getDestination();
	}


}
